<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>实际数据管理</title>
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css"  media="all">
</head>
<body>
<input type="hidden" id="dateOne">
<input type="hidden" id="dateTwo">


<table class="layui-hide" id="test" lay-filter="test"></table>

<!--头部工具栏-->
<script type="text/html" id="toolbarDemo">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" lay-verify="date" placeholder="开始时间" autocomplete="off" class="layui-input" style="width: 150px">
            </div>
        </div>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date1" lay-verify="date" placeholder="结束时间" autocomplete="off" class="layui-input" style="width: 150px">
            </div>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-sm" lay-event="isAll">查询</button>
        </div>
        <div class="layui-input-inline" style="margin-left: 20px">
            <button class="layui-btn layui-btn-sm" lay-event="addData">录入数据</button>
        </div>
    </div>
</script>

<!--右侧工具栏-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="see">查看</a>
    <a class="layui-btn layui-btn-xs"  lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="isva">
    {{# if( d.isva == 1 ) { }}
   <p style="color: #ac2925">已提交</p>
    {{# }else if( d.isva == 2 ){ }}
    <p style="color: #00aced">暂存</p>
    {{# } }}
</script>

<script>
    var sportId=getQueryString("sportId");
    var table2
    layui.use(['table','layedit', 'laydate'], function(){
        var table = layui.table
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        table2=table.render({
            elem: '#test'
            ,url:'../../AtsDataBatch/selectFindAll?sportId='+sportId
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '用户数据表'
            ,cols: [[
                {field:'batchName', title:'批次名称', width:200}
                ,{field:'year', title:'年', width:100}
                ,{field:'month', title:'月', width:50}
                ,{field:'batchDate', title:'录入时间', width:120}
                ,{field:'athleteName', title:'运动员姓名', width:100}
                ,{field:'sprotName', title:'运动项目名称', width:150}
                ,{field:'isva', title:'状态', width:150,toolbar:'#isva', width:100}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page: true
        });

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            /*//日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });*/
            switch(obj.event){
                case 'addData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    layer.msg('录入数据');
                    layer.open({
                        type: 2,
                        title: '增加操作',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['90%', '90%'],
                        content: '../atsData/AtsData.html?sportId='+sportId
                    });
                    break;
                case 'isAll':
                    layer.msg("查询")
                    $("#dateOne").val($("#date").val())
                    $("#dateTwo").val($("#date1").val())
                    table2.reload({
                       // url:'../../AtsDataBatch/selectFindAll?sportId='+sportId+'&remark='+loginObj.manager.filId,
                        where : {
                            startDate:$("#date").val(),
                            endDate:$("#date1").val(),
                            sportId:sportId
                        },
                        page : {
                            curr : 1
                        }
                    })
                    $("#date").val($("#dateOne").val())
                    $("#date1").val($("#dateTwo").val())
                    //日期
                    laydate.render({
                        elem: '#date'
                    });
                    laydate.render({
                        elem: '#date1'
                    });
                    break;
                case 'allData':
                    table2.reload({
                        url:'../../AtsDataBatch/selectFindAll',
                        where : {
                            sportId:sportId
                        },
                        page : {
                            curr : 1
                        }
                    })
                    //日期
                    laydate.render({
                        elem: '#date'
                    });
                    laydate.render({
                        elem: '#date1'
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    var url="../../AtsDataBatch/deleteById";
                    $.post(url,data,function (obj) {
                        if(obj.num==1){
                            table2.reload();
                            obj.del();
                        }else{
                            layer.msg("删除失败")
                        }
                    },"json")
                    layer.close(index);
                });
            }else if(obj.event === 'see'){
                layer.open({
                    type: 2,
                    title: '查看',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: '../AtsDataShow/AtsDataShow.html?batchId='+data.batchId
                });
            } else if(obj.event === 'edit'){
                layer.msg('编辑操作');
                layer.open({
                    type: 2,
                    title: '操作',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: '../atsData/AtsData.html?sportId='+data.sportId+"&batchId="+data.batchId
                });
            }
        });
    });
</script>
</body>
</html>